package com.yanqu.road.server.cmd.cricket.court.cross;

import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.pb.cricket.CricketProto;
import com.yanqu.road.server.cmd.base.AbstractCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.gameplayer.module.cricket.CricketModule;
import com.yanqu.road.server.protocol.GameProtocol;
import com.yanqu.road.server.protocol.Protocol;

@Cmd(code = GameProtocol.S_CRICKET_SYNC_DATA_FROM_CROSS, desc = "蛐蛐跨服数据同步回包")
public class CricketSyncDataFromCrossCmd extends AbstractCommand {

    private boolean systemOpen;
    private int round;

    private long rewardTime;

    private long endTime;

    private boolean haveTopRank;

    @Override
    public boolean parseData(YanQuMessage packet) throws Exception {
        CricketProto.CrossCricketSyncDataRespMsg respMsg = CricketProto.CrossCricketSyncDataRespMsg.parseFrom(packet.getBytes());
        systemOpen = respMsg.getSystemOpen();
        round = respMsg.getRound();
        rewardTime = respMsg.getRewardTime();
        endTime = respMsg.getEndTime();
        haveTopRank = respMsg.getHaveTopRank();
        return true;
    }

    @Override
    public void execute(GamePlayer player, YanQuMessage packet) throws Exception {
        // 更新下竞技场数据
        player.getModule(CricketModule.class).changeCourtRound(round);
        // 同步给用户
        CricketProto.CricketCourtDataSyncRespMsg.Builder builder = CricketProto.CricketCourtDataSyncRespMsg.newBuilder();
        builder.setSystemOpen(systemOpen);
        builder.setRound(round);
        builder.setRewardTime(rewardTime);
        builder.setEndTime(endTime);
        builder.setHaveTopRank(haveTopRank);
        player.sendPacket(Protocol.U_CRICKET_COURT_SYNC_DATA, builder);
    }

    @Override
    public void sendData(GamePlayer player) {

    }
}
